package org.ninjarope.cinderstained.main.gameplay;

import java.util.ArrayList;

import org.ninjarope.cinderstained.main.engine.Game;
import org.ninjarope.cinderstained.main.gameplay.definition.GameActor;
import org.ninjarope.cinderstained.main.gameplay.definition.GameTerrain;
import org.ninjarope.cinderstained.main.gameplay.definition.Stat;
import org.ninjarope.cinderstained.main.gameplay.definition.damage.Damage;
import org.ninjarope.cinderstained.main.gameplay.definition.pool.Pool;
import org.ninjarope.cinderstained.main.gameplay.definition.pool.PoolMember;
import org.ninjarope.cinderstained.main.screens.TestingStuff;

import com.badlogic.gdx.math.Vector2;

public class Creep extends GameActor implements PoolMember<Creep> {
	public Stat health;
	public Stat moveSpeed;
	public ArrayList<Vector2> waypoints;
	public int nextWaypoint;
	public float spawnTime;

	public Creep(){
		super();
		Pool<Stat> p = Game.pools("stats");
		health = p.request();
		moveSpeed = p.request();
		nextWaypoint=0;
	}
	@Override
	public Creep assimilate(Creep def) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void onBirth() {
		// TODO Auto-generated method stub

	}

	@Override
	public void onTakeDamage(GameActor[] attacker) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onAttack(Damage dmg) {
		this.health.current -= dmg.current;
	}

	@Override
	public void onWalk(GameTerrain terrain) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onTick() {
		// TODO Auto-generated method stub

	}

	@Override
	public void onStep() {
		// TODO Auto-generated method stub

	}

	@Override
	public boolean onDeath() {
		// TODO Auto-generated method stub
		return true;
	}
	
	/**
	 * Method for moving creep toward the next waypoint
	 */
	public void calculateMove(float deltaTime){
		// pomeranje objekta
					if (nextWaypoint < this.waypoints.size()) {
						if (position.dst(waypoints.get(nextWaypoint)) < 1) {
							nextWaypoint++;
						} else {
							Vector2 tempV = new Vector2(
									this.waypoints.get(nextWaypoint).x
											- position.x,
									this.waypoints.get(nextWaypoint).y
											- position.y);
							tempV = TestingStuff.normalize(tempV);
							move(tempV.x * 100 * deltaTime, tempV.y * 100 * deltaTime);
						}
					} else {
						// ukoliko je objekat stigao do zadnjeg waypoint-a
						move(100 * deltaTime, 0);
					}
					// provera da li postoji kula kojoj je u dometu i koja moze da ga
					// napadne
	}
}
